package cz.czu.pef.DataModelling.dao;

import java.util.Collection;
import java.util.List;

import cz.czu.pef.DataModelling.dao.impl.CustomFilterField;
import cz.czu.pef.DataModelling.dao.impl.CustomSortField;

/**
 * Contains CRUD generic operations for each Entity
 * 
 * 
 */
public interface DaoBasic<T>
{
	/**
	 * Stores entity in database
	 * 
	 * @param entity
	 *            to store
	 * @return generated id
	 */
	T save(T entity);

	/**
	 * Retrieve entity form database, identified by its id
	 * 
	 * @param id
	 * @return
	 */
	T getByStringId(String id);

	/**
	 * Stores / updates entity in database
	 * 
	 * @param entity
	 */
	void saveOrUpdate(T entity);


	/**
	 * Retrieve entity form database, identified by its id
	 * 
	 * @param id
	 * @return
	 */
	T getById(long id);

	/**
	 * Retrieve entity form database, identified by its id
	 * 
	 * @param id
	 * @return
	 */
	T getByIdLocked(long id);

	/**
	 * Updates already stored entity
	 * 
	 * @param entity
	 * @return
	 */
	void update(T entity);

	/**
	 * Removes entity from database
	 * 
	 * @param entity
	 * @return
	 */
	void delete(T entity);

	/**
	 * Removes entity from database by its unique ID
	 * 
	 * @param idValue
	 * @return
	 */
	void deleteById(String idValue);

	/**
	 * Merges an entity
	 * 
	 * @param entity
	 * @return newly merged entity
	 */
	T merge(T entity);

	public Long count();

	public Long countWithFilter(List<CustomFilterField> filterFields);

	public List<T> findByAttributeIn(final String attribName, final Collection<? extends Object> value);

	public List<T> findByAttribute(final String attribName, final Object value);

	public T findByAttributeUniqueResult(final String attribName, final Object value);

	public List<T> findAll();

	public List<T> findAllByRange(int firstRow, int endRow);
	
	public List<T> findAllByRangeWithFilter(int firstRow, int endRow, List<CustomFilterField> filterFields);

	public List<T> findAllByRangeWithFilterAndSort(int firstRow, int endRow, List<CustomFilterField> filterFields, List<CustomSortField> sortFields);
}
